package cn.edu.sgu.www.mhxysy.service.equipment.impl;

import cn.edu.sgu.www.mhxysy.entity.equipment.ForgeType;
import cn.edu.sgu.www.mhxysy.mapper.equipment.ForgeTypeMapper;
import cn.edu.sgu.www.mhxysy.service.equipment.ForgeTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Service
public class ForgeTypeServiceImpl implements ForgeTypeService {

    private final ForgeTypeMapper forgeTypeMapper;

    @Autowired
    public ForgeTypeServiceImpl(ForgeTypeMapper forgeTypeMapper) {
        this.forgeTypeMapper = forgeTypeMapper;
    }

    @Override
    public List<ForgeType> selectAll() {
        return forgeTypeMapper.selectList(null);
    }

    @Override
    public ForgeType selectById(Integer id) {
        return forgeTypeMapper.selectById(id);
    }

    @Override
    public ForgeType selectByParentId(Integer id) {
        ForgeType forgeType = forgeTypeMapper.selectById(id);

        // 父级类型的处理，专属装备应显示为其父打造类型：强化打造
        Integer parentId = forgeType.getParentId();

        if (parentId != null) {
            String iconClass = forgeType.getIconClass();

            forgeType = forgeTypeMapper.selectById(parentId);

            forgeType.setIconClass(iconClass);
        }

        return forgeType;
    }

}